package com.ql.service.keshi.impl;

import com.ql.dao.keshi.GonnengMapper;
import com.ql.pojo.keshi.Gonneng;
import com.ql.service.keshi.GonnengService;
import com.ql.utils.PageHelper;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("gonnengService")
public class GonnengServiceImpl implements GonnengService {
    private static final Logger LOGGER = Logger.getLogger(FangsheServiceImpl.class);
    @Resource
    private GonnengMapper gonnengMapper;
    @Override
    public boolean addNewGonneng(Gonneng gonneng) {
        int row = 0;
        try {
            row = gonnengMapper.save(gonneng);
            if(row != 1){
                LOGGER.debug(" 保存放射科信息失败！");
                return false;
            }else{
                LOGGER.debug(" 保存放射科信息成功！");
                return true;
            }
        } catch (Exception e) {
            //e.printStackTrace();
            LOGGER.error("添加放射科信息异常》》》"+e.getMessage());
            return false;
        }
    }

    @Override
    public List<Gonneng> getAllGonneng(PageHelper ph, String qryName) {
        List<Gonneng> gonnengList = new ArrayList<>();

        try {
            //add:更新总条数,
            //add 18.11.22:增加分页的条件
            ph.setTotalCount(gonnengMapper.qryCount(qryName));

            gonnengList = gonnengMapper.qryAll((ph.getCurrentPageNo()-1)*ph.getPageSize(),ph.getPageSize(),qryName);
            if (gonnengList.size() <= 0) {
                LOGGER.debug("查询为空！");
                //return userList;
            } else {
                LOGGER.debug(" 查询成功！");
            }
        } catch (Exception e) {
            LOGGER.error("异常：" + e.getMessage());
            //return userList;
        }
        return gonnengList;
    }


    /*cg病案查询*/
    @Override
    public Gonneng getGNKByUId(int UId) {
        Gonneng gnkByUId = null;
        try {
            gnkByUId = gonnengMapper.qryGNKByUId(UId);
            if(gnkByUId == null){
                LOGGER.debug("GonnengServiceImpl.getGNKByUId 查询为空");
            }else {
                LOGGER.debug("GonnengServiceImpl.getGNKByUId 查询成功");
            }
        } catch (Exception e) {
            LOGGER.error("GonnengServiceImpl.getGNKByUId 查询异常》》》》"+e.getMessage());
            gnkByUId = new Gonneng();
        }

        return gnkByUId;
    }
}
